package com.example.demo.controller;

import com.example.demo.entity.Emp;
import com.example.demo.entity.EmpQueryParam;
import com.example.demo.entity.PageBean;
import com.example.demo.entity.Result;
import com.example.demo.service.Impl.EmpServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {
    @Autowired
    private EmpServiceImpl empService;

    @GetMapping
    public Result page(EmpQueryParam param){
        log.info("请求参数：{}",param);
        PageBean pageBean =  empService.page(param);
        return Result.success(pageBean);
    }
    @PostMapping
    public Result save(@RequestBody Emp emp){
        log.info("请求参数：{}",emp);
        empService.save(emp);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info(" 批量删除emp的ID：{}",ids);
        empService.deleteByids(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("根据emp的ID：{} 返回详细信息",id);
        Emp emp = empService.findById(id);
        return Result.success(emp);
    }
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改emp：{}",emp);
        empService.update(emp);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getAllEmp(){
        log.info("返回所有员工信息");
        return Result.success(empService.getAllEmp());
    }
}
